﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Collections.ObjectModel;
using System.Data.SqlClient;
using VisaCRM.Modules.Admin.Model;
using VisaCRM.Common.Helper;

namespace VisaCRM.Modules.Admin.Gateway
{
    class WhereHearGateway
    {
        public ObservableCollection<WhereHear> GetAllWhereHear()
        {
            ObservableCollection<WhereHear> allWhereHear = new ObservableCollection<WhereHear>();
            DataTable dt = new DataTable();
            dt = DBHelper.GetDataTable(QueryProvider.MakeSQLQueryToFetchWhereHearList());
            if (dt.Rows.Count <= 0)
            {
                return allWhereHear;
            }
            foreach (DataRow dataRow in (InternalDataCollectionBase)dt.Rows)
            {
                allWhereHear.Add(new WhereHear()
                {
                    WhereHearId = Convert.ToInt32(dataRow["WhereHear_ID"].ToString()),
                    WhereHearText = dataRow["WhereHear_Text"].ToString(),
                    WhereHearWebsite = Convert.ToInt32(dataRow["WhereHear_Website"].ToString()),
                });
            }
            return allWhereHear;
        }

        public void SaveNewWhereHearToDatabase(string wherehear,int wherehearwebsite)
        {
            string query = QueryProvider.MakeSQLQueryToInsertWhereHearToDatabase(wherehear, wherehearwebsite);
            DBHelper.ExecuteSqlQuery(query);
        }

        public void EditWhereHearToDatabase(string wherehear, int wherehearwebsite, int rowid)
        {
            string query = QueryProvider.MakeSQLQueryToEditWhereHearToDatabase(wherehear, wherehearwebsite, rowid);
            DBHelper.ExecuteSqlQuery(query);

        }

        public void DeleteWhereHearFromDatabase(int rowid)
        {
            string query = QueryProvider.MakeSQLQueryToDeleteWhereHearFromDatabase(rowid);
            DBHelper.ExecuteSqlQuery(query);
        }

    }
}
